/**
 * 是否微前端
 */
export const isMicroApp = () => {
  return window.__MICRO_APP_ENVIRONMENT__;
};

/**
 * 基础路由
 */
export const microAppBaseRouter = () => {
  return isMicroApp() ? window.__MICRO_APP_BASE_ROUTE__ || "/" : "/";
};

/**å
 * 控制主应用路由
 */
export const microAppMainRouter = (routerFun, pathObj) => {
  if (!isMicroApp()) return;
  const baseRouter = window.microApp && window.microApp.router.getBaseAppRouter();
  baseRouter[routerFun](pathObj);
};

/**
 * 发送数据
 */
export const microAppSendData = (data, callback) => {
  if (!isMicroApp()) return;
  window.microApp && window.microApp.dispatch(data, callback);
};

/**
 * 强制发送数据
 */
export const microAppForceSendData = (data, callBack) => {
  if (!isMicroApp()) return;
  window.microApp && window.microApp.forceDispatch(data, callBack);
};

/**
 * 接收全局数据
 */
export const getGlobalData = () => {
  if (!isMicroApp()) return;
  return window.microApp.getGlobalData();
};
